<template>
	<view class="jyq_user">

		
		<view class="cu-form-group ">
			<view class="title">用户名</view>
			<input placeholder="随便取名" name="input" v-model="form.user_name"></input>
		</view>
		<view class="pl30 pr30 pt10 text-gray">
			首次使用本工具，请先提交用户名信息，用户名仅供展示，可任意命名
		</view>
		<view class="p30">
			<button class="cu-btn block bg-red margin-tb-sm lg" type="" @click="submit">开始使用</button>
		</view>
		<version></version>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				cookieKey:"cookie_open_id",
				form:{
					user_name:"",
					cookie_open_id:"",
				}
			}
		},
		onLoad() {
			let cookie_open_id=this.$utils.getStorage(this.cookieKey);
			 if(!cookie_open_id){
				cookie_open_id=this.$utils.getCookieOpenId();
				this.$utils.setStorage(this.cookieKey,cookie_open_id)
			}
			this.form.cookie_open_id=cookie_open_id; 
		},
		methods: {
			async submit(){
				let url="/user/createUser";
				let params=this.form;
				let [err,response]=await this.$to(this.$request(url,params));
				console.log("res:",err,response);
				let userModel=response.data;
				this.$utils.setStorage("token",userModel.token);
				this.$utils.setStorage("userModel",userModel);
				//走到这里就是成功了
				uni.redirectTo({
					url:"../jinyouquan/add"
				});
			}
		}
	}
</script>

<style>
	.jyq_user {}
</style>
